<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :before-close="handleDialogClose"
    :lock-scroll="false"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    class="subcribe-common-dialog small-common-dialog-size"
  >
    <DialogTitle title="库存预警通知人" font-size="16px" style="margin-bottom:20px;">
      <el-tooltip placement="right">
        <div slot="content">预警设置的人员是针对全部商品</div>
        <tipIcon is-diy/>
      </el-tooltip>
    </DialogTitle>
    <div class="flex-center">
      <div class="input-label">预警通知人员:</div>
      <selectWithUserLoad
        v-model="notifyUsers"
        :default-list="selectedNotifyUsers"
        :extend-params="{ userStatus: 1, type: 1 }"
        style="width:240px;"
        placeholder="请选择人员"
        key-name="id"
        value-type="object"
        label-name="userName"
        multiple
        filterable
        clearable/>
    </div>
    <div class="dialog-footer">
      <el-button class="ok" type="primary" @click="handleConfirm">确定</el-button>
      <el-button class="cancel-btn-style" type="info" @click="handleDialogClose">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import DialogTitle from '@/components/Title';
import selectWithUserLoad from '@/components/Common/selectWithUserLoad';
import { storeNotifyUsers } from '@/api/setting';

export default {
  components: {
    DialogTitle,
    selectWithUserLoad
  },
  props: {},
  data() {
    return {
      dialogVisible: false,
      selectedNotifyUsers: [],
      notifyUsers: []
    };
  },
  methods: {
    handleDialogClose() {
      this.dialogVisible = false;
      this.selectedNotifyUsers = [];
      this.notifyUsers = [];
    },
    handleConfirm() {
      const ids = this.notifyUsers.map(user => user.id).join();
      storeNotifyUsers({ ids }).then(res => {
        if (res.code === 200) {
          this.$emit('storeCallback');
          this.handleDialogClose();
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.icon-info {
  cursor: pointer;
  color: #ccc;
  margin-left: 4px;
  &:hover {
    color: #406EFF !important;
  }
}
.input-label {
  margin-right: 12px;
  line-height: 32px;
  color: #666;
  align-self: self-start;
}
.input-box {
  width: 240px;
  ::v-deep .el-input__inner {
    height: 32px;
    line-height: 32px;
    width: 240px;
    font-size: 14px;
  }
  .input-tip {
    margin-top: 4px;
    font-size: 12px;
    color: #999;
  }
}
.dialog-footer {
  display: flex;
  justify-content: center;
  margin-top: 25px;
  .ok {
    width: 120px;
    font-size: 16px;
    padding: 8px 20px;
  }
  .cancel-btn-style {
    font-size: 14px;
    padding: 8px 20px;
    margin-left: 16px !important;
  }
}
</style>
